<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <div id="div1">Hello Yunmu</div>
    <div>
      <button id="btnSplit">拆分</button>
      <button id="btnNormalize">合并</button>
    </div>
    <script>
      const div1El = document.getElementById("div1");
      btnSplit.addEventListener("click", function () {
        console.log("splitText before:", div1El.childNodes, div1El.childNodes[0].nodeValue);
        // 从第五个字母开始分割成独立的两个兄弟文本节点
        div1El.firstChild.splitText(5);
        console.log("splitText after:", div1El.childNodes, div1El.childNodes.length);
      });
      btnNormalize.addEventListener("click", function () {
        // 合并
        div1El.normalize();
        console.log("normalize:", div1El.childNodes, div1El.childNodes.length);
      });
    </script>
  </body>
</html>
